package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.WaterDianPageDto;
import com.example.entity.WaterDian;
import com.example.service.WaterDianService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/admin/waterdian")
public class WaterDianController {
    @Autowired
    private WaterDianService waterDianService;

    @GetMapping("/page")
    public Result<PageResult> page(WaterDianPageDto waterDianPageDto) {
        PageResult page =  waterDianService.page(waterDianPageDto);
        return Result.success(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody WaterDian waterDian){
        waterDianService.add(waterDian);
        return Result.success();
    }

    @DeleteMapping("{dno}")
    public Result deleteByDno(@PathVariable String dno){
        waterDianService.deleteByDno(dno);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody WaterDian waterDian){
        waterDianService.update(waterDian);
        return Result.success();
    }
}
